View Javadoc
1 /* 2 AntMake 3 4 Copyright (C) 2004 Jose San Leandro Armend?riz 5 jsanleandro@yahoo.es 6 chousz@yahoo.com 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public 10 License as published by the Free Software Foundation; either 11 version 2 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 General Public License for more details. 17 18 You should have received a copy of the GNU General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 Thanks to ACM S.L. for distributing this library under the GPL license. 23 Contact info: jsanleandro@yahoo.es 24 Postal Address: c/Playa de Lagoa, 1 25 Urb. Valdecaba?as 26 Boadilla del monte 27 28660 Madrid 28 Spain 29 30 ****************************************************************************** 31 * 32 * Filename: $RCSfile: TopMakefileAmTemplate.java,v $ 33 * 34 * Author: Jose San Leandro Armend?riz 35 * 36 * Description: Template to generate top-level Makefile.am files. 37 * 38 * Last modified by: $Author: chous $ at $Date: 2004/02/01 17:22:26 $ 39 * 40 * File version: $Revision: 1.3 $ 41 * 42 * Project version: $Name: $ 43 * 44 * $Id: TopMakefileAmTemplate.java,v 1.3 2004/02/01 17:22:26 chous Exp $ 45 * 46 */ 47 package org.acmsl.antmake; 48 49 /* 50 * Importing some JDK classes. 51 */ 52 import java.io.File; 53 import java.text.MessageFormat; 54 import java.util.ArrayList; 55 import java.util.Iterator; 56 import java.util.Collection; 57 58 /*** 59 * Template to generate top-level <i>Makefile.am</i> files. 60 * @author <a href="mailto:jsanleandro@yahoo.es" 61 >Jose San Leandro</a> 62 * @version $Revision: 1.3 $ 63 */ 64 public abstract class TopMakefileAmTemplate 65 { 66 /*** 67 * The default header. 68 */ 69 public static final String DEFAULT_HEADER = 70 "#\n" 71 + "# AntMake\n" 72 + "#\n" 73 + "# Copyright (C) 2004 Jose San Leandro Armend?riz\n" 74 + "# jsanleandro@yahoo.es\n" 75 + "# chousz@yahoo.com\n" 76 + "#\n" 77 + "# This library is free software; you can redistribute it and/or\n" 78 + "# modify it under the terms of the GNU General Public\n" 79 + "# License as published by the Free Software Foundation; either\n" 80 + "# version 2 of the License, or (at your option) any later " 81 + "version.\n" 82 + "#\n" 83 + "# This library is distributed in the hope that it will be " 84 + "useful,\n" 85 + "# but WITHOUT ANY WARRANTY; without even the implied warranty " 86 + "of\n" 87 + "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " 88 + "GNU\n" 89 + "# General Public License for more details.\n" 90 + "#\n" 91 + "# You should have received a copy of the GNU General Public\n" 92 + "# License along with this library; if not, write to the Free " 93 + "Software\n" 94 + "# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA " 95 + "02111-1307 USA\n" 96 + "#\n" 97 + "# Thanks to ACM S.L. for distributing this library under the GPL " 98 + "license.\n" 99 + "# Contact info: jsanleandro@yahoo.es\n" 100 + "# Postal Address: c/Playa de Lagoa, 1\n" 101 + "# Urb. Valdecaba?as\n" 102 + "# Boadilla del monte\n" 103 + "# 28660 Madrid\n" 104 + "# Spain\n" 105 + " #################################################################" 106 + "#############\n" 107 + " #\n" 108 + " # Filename: $" + "RCSfile: $\n" 109 + " #\n" 110 + " # Author: AntMake\n" 111 + " #\n" 112 + " # Description: Defines the rules required to successfully build\n" 113 + " # the project in any supported platform.\n" 114 + " #\n" 115 + " # Last modified by: $" + "Author: $ at $" + "Date: $\n" 116 + " #\n" 117 + " # File version: $" + "Revision: $\n" 118 + " #\n" 119 + " # Project version: $" + "Name: $\n" 120 + " #\n" 121 + " # $" + "Id: $\n" 122 + " #\n\n"; 123 124 /*** 125 * The default Make-Rules body. 126 */ 127 public static final String DEFAULT_BODY = 128 "## Process this with automake to create Makefile.in\n" 129 + "\n" 130 + "JAVATOP =\n" 131 + "SUBDIRS = {2}\n" // top-level subfolders 132 + "javadir=$(datadir)/java\n" 133 + "\n" 134 + "JAR = jar\n" 135 + "\n" 136 + "# Build a .zip archive from the compiled classes.\n" 137 + "\n" 138 + "{0}-@VERSION@-compiled.zip:\n" // project name 139 + " zip -q -r -n .class $@ {2} -i ''*.class''\n" // top-level subfolders 140 + "\n" 141 + "JAR_DEPS = {3}\n" // jar deps subtemplate 142 + "\n" 143 + "{0}-@VERSION@.jar: $(JAR_DEPS)\n" // project name 144 + " $(JAR) cf {0}-@VERSION@.jar //\n" 145 + " `find {2} -name ''*.class'' -print`\n" 146 + "\n" 147 + "dist-{0}-@VERSION@.jar:\n" 148 + " srcdir=`(cd $(srcdir); /bin/pwd)` //\n" 149 + " && rm -rf tmpdir //\n" 150 + " && mkdir tmpdir //\n" 151 + " && cd tmpdir //\n" 152 + " && $$srcdir/configure //\n" 153 + " && $(MAKE) //\n" 154 + " && $(JAR) cf //\n" 155 + " ../{0}-@VERSION@.jar //\n" 156 + " `find . -name ''*.class'' -print` //\n" 157 + " && cd .. && rm -rf tmpdir\n" 158 + "\n" 159 + "{0}-@VERSION@-src.zip: {0}-@VERSION@.tar.gz\n" 160 + " mkdir zip-temp\n" 161 + " cd zip-temp ;//\n" 162 + " tar xzf ../{0}-@VERSION@.tar.gz; //\n" 163 + " zip -q -r ../{0}-@VERSION@-src.zip {0}-@VERSION@\n" 164 + " rm -rf zip-temp\n" 165 + "\n" 166 + "{0}-compiled.zip: {0}-@VERSION@-compiled.zip\n" 167 + "{0}.jar: {0}-@VERSION@.jar\n" 168 + "{0}-src.zip: {0}-@VERSION@-src.zip\n" 169 + "\n" 170 + "#EXTRA_DIST = debian/control debian/rules debian/changelog debian/dirs //\n" 171 + "# config.guess config.sub install-sh ./mkinstalldirs make{0}.bat //\n" 172 + "# libtool.m4 ltmain.sh //\n" 173 + "# build.xml build.properties //\n" 174 + "# jar-manifest Make-rules\n" 175 + "\n" 176 + "HTML_HOME = $$HOME/public_html\n" 177 + "JAVADOC_DIR = $$HOME/{1}/api\n" 178 + "JAVADOC_PACKAGES = //\n" 179 + " {4}\n" // project packages 180 + "JAVADOC = javadoc\n" 181 + "JAVADOC_FLAGS = -J-Xms40m -J-Xmx40m\n" 182 + "\n" 183 + "MAINTAINERCLEANFILES = makejavadoc.bat\n" 184 + "MOSTLYCLEANFILES = tmp *.o {0}1$(exeext)\n" 185 + "CLEANFILES = *.jar\n" 186 + "\n" 187 + "install-javadoc-html:\n" 188 + " rm -rf $(JAVADOC_DIR)/*\n" 189 + " -mkdir $(JAVADOC_DIR)\n" 190 + " $(JAVADOC) $(JAVADOC_FLAGS) -sourcepath .:$(top_srcdir) -d $(JAVADOC_DIR) $(JAVADOC_PACKAGES)\n" 191 + " cp $(srcdir)/COPYING $(JAVADOC_DIR)/COPYING\n" 192 + "\n" 193 + "install-html: install-javadoc-html\n" 194 + " cp $(srcdir)/NEWS $(HTML_HOME)/{1}/News.txt\n" 195 + " cd doc; make install-html HTML_HOME=\"$(HTML_HOME)\"\n" 196 + " cd gnu; make install-html HTML_HOME=\"$(HTML_HOME)\"\n" 197 + "\n" 198 + "install-data-am: install-jar\n" 199 + "install-jar:\n" 200 + " @$(NORMAL_INSTALL)\n" 201 + " $(mkinstalldirs) $(DESTDIR)$(javadir)\n" 202 + " $(INSTALL_DATA) {0}-@VERSION@.jar //\n" 203 + " $(DESTDIR)$(javadir)/{0}-@VERSION@.jar\n" 204 + " cd $(DESTDIR)$(javadir) && rm -f {0}.jar //\n" 205 + " && $(LN_S) {0}-@VERSION@.jar {0}.jar\n" 206 + "\n" 207 + "uninstall-local: uninstall-jar\n" 208 + "uninstall-jar:\n" 209 + " rm -f $(DESTDIR)$(javadir)/{0}-@VERSION@.jar //\n" 210 + " $(DESTDIR)$(javadir)/{0}.jar\n" 211 + "\n" 212 + "all: {0}-@VERSION@.jar\n" 213 + "\n" 214 + "distall: distcheck dist-{0}-@VERSION@.jar\n" 215 + "\n"; 216 217 /*** 218 * The default jar deps subtemplate. 219 */ 220 public static final String DEFAULT_JAR_DEPS_SUBTEMPLATE = 221 "./{0}/java-classes.stamp "; // folders with Java sources 222 223 /*** 224 * The header. 225 */ 226 private String m__strHeader; 227 228 /*** 229 * The Makefile.am body. 230 */ 231 private String m__strBody; 232 233 /*** 234 * The jar deps subtemplate. 235 */ 236 private String m__strJarDepsSubtemplate; 237 238 /*** 239 * The project name. 240 */ 241 private String m__strProjectName; 242 243 /*** 244 * The top-level folder list. 245 */ 246 private Collection m__cTopFolders; 247 248 /*** 249 * The leaf folder list. 250 */ 251 private Collection m__cLeafFolders; 252 253 /*** 254 * The project packages. 255 */ 256 private Collection m__cPackages; 257 258 /*** 259 * Builds a TopMakefileAmTemplate using given information. 260 * @param header the header. 261 * @param body the body. 262 * @param jarDepsSubtemplate the JAR_DEPS subtemplate. 263 * @param projectName the project name. 264 */ 265 public TopMakefileAmTemplate( 266 String header, 267 String body, 268 String jarDepsSubtemplate, 269 String projectName) 270 { 271 inmutableSetHeader(header); 272 inmutableSetBody(body); 273 inmutableSetJarDepsSubtemplate(jarDepsSubtemplate); 274 inmutableSetProjectName(projectName); 275 } 276 277 /*** 278 * Builds a TopMakefileAmTemplate using given information. 279 * @param projectName the project name. 280 */ 281 public TopMakefileAmTemplate(String projectName) 282 { 283 this( 284 DEFAULT_HEADER, 285 DEFAULT_BODY, 286 DEFAULT_JAR_DEPS_SUBTEMPLATE, 287 projectName); 288 } 289 290 /*** 291 * Specifies the header. 292 * @param header the new header. 293 */ 294 private void inmutableSetHeader(String header) 295 { 296 m__strHeader = header; 297 } 298 299 /*** 300 * Specifies the header. 301 * @param header the new header. 302 */ 303 protected void setHeader(String header) 304 { 305 inmutableSetHeader(header); 306 } 307 308 /*** 309 * Retrieves the header. 310 * @return such information. 311 */ 312 public String getHeader() 313 { 314 return m__strHeader; 315 } 316 317 /*** 318 * Specifies the body. 319 * @param body the new body. 320 */ 321 private void inmutableSetBody(String body) 322 { 323 m__strBody = body; 324 } 325 326 /*** 327 * Specifies the body. 328 * @param body the new body. 329 */ 330 protected void setBody(String body) 331 { 332 inmutableSetBody(body); 333 } 334 335 /*** 336 * Retrieves the body. 337 * @return such information. 338 */ 339 public String getBody() 340 { 341 return m__strBody; 342 } 343 344 /*** 345 * Specifies the JAR_DEPS subtemplate. 346 * @param jarDepsSubtemplate the new subtemplate. 347 */ 348 private void inmutableSetJarDepsSubtemplate(String jarDepsSubtemplate) 349 { 350 m__strJarDepsSubtemplate = jarDepsSubtemplate; 351 } 352 353 /*** 354 * Specifies the JAR_DEPS subtemplate. 355 * @param jarDepsSubtemplate the new subtemplate. 356 */ 357 protected void setJarDepsSubtemplate(String jarDepsSubtemplate) 358 { 359 inmutableSetJarDepsSubtemplate(jarDepsSubtemplate); 360 } 361 362 /*** 363 * Retrieves the JAR_DEPS subtemplate. 364 * @return such information. 365 */ 366 public String getJarDepsSubtemplate() 367 { 368 return m__strJarDepsSubtemplate; 369 } 370 371 /*** 372 * Specifies the project name. 373 * @param projectName the new project name. 374 */ 375 private void inmutableSetProjectName(String projectName) 376 { 377 m__strProjectName = projectName; 378 } 379 380 /*** 381 * Specifies the project name. 382 * @param projectName the new project name. 383 */ 384 protected void setProjectName(String projectName) 385 { 386 inmutableSetProjectName(projectName); 387 } 388 389 /*** 390 * Retrieves the project name. 391 * @return such information. 392 */ 393 public String getProjectName() 394 { 395 return m__strProjectName; 396 } 397 398 /*** 399 * Specifies the top-level folders. 400 * @param folders the folder list. 401 */ 402 protected void setTopFolders(Collection folders) 403 { 404 m__cTopFolders = folders; 405 } 406 407 /*** 408 * Retrieves the top-level folders. 409 * @return such collection. 410 */ 411 protected Collection getTopFolders() 412 { 413 return m__cTopFolders; 414 } 415 416 /*** 417 * Adds a top-level folder. 418 * @param folder the top-level folder to add. 419 */ 420 public void addTopFolder(String folder) 421 { 422 setTopFolders(add(getTopFolders(), folder)); 423 } 424 425 /*** 426 * Specifies the leaf folders. 427 * @param folders the folder list. 428 */ 429 protected void setLeafFolders(Collection folders) 430 { 431 m__cLeafFolders = folders; 432 } 433 434 /*** 435 * Retrieves the leaf folders. 436 * @return such collection. 437 */ 438 protected Collection getLeafFolders() 439 { 440 return m__cLeafFolders; 441 } 442 443 /*** 444 * Adds a leaf-level folder. 445 * @param folder the leaf folder to add. 446 */ 447 public void addLeafFolder(String folder) 448 { 449 setLeafFolders(add(getLeafFolders(), folder)); 450 } 451 452 /*** 453 * Specifies the packages. 454 * @param packages the package list. 455 */ 456 protected void setPackages(Collection packages) 457 { 458 m__cPackages = packages; 459 } 460 461 /*** 462 * Retrieves the packages. 463 * @return such collection. 464 */ 465 protected Collection getPackages() 466 { 467 return m__cPackages; 468 } 469 470 /*** 471 * Adds a package. 472 * @param concretePackage the package to add. 473 */ 474 public void addPackage(String concretePackage) 475 { 476 setPackages(add(getPackages(), concretePackage)); 477 } 478 479 /*** 480 * Adds an item to given collection.. 481 * @param container the collection. 482 * @param item the item to add. 483 * @return the given collection, or a newly-created one 484 * if <code>container</code> was null. 485 */ 486 protected Collection add(Collection container, String item) 487 { 488 Collection result = null; 489 490 if (item != null) 491 { 492 if (container == null) 493 { 494 result = new ArrayList(); 495 } 496 else 497 { 498 result = container; 499 } 500 501 if (!result.contains(item)) 502 { 503 result.add(item); 504 } 505 } 506 507 return result; 508 } 509 510 /*** 511 * Retrieves the weaved top-level <i>Makefile.am</i> file contents. 512 * @return such contents. 513 */ 514 public String toString() 515 { 516 StringBuffer t_sbResult = new StringBuffer(); 517 518 String t_strProjectName = getProjectName(); 519 Collection t_cTopFolders = getTopFolders(); 520 Collection t_cLeafFolders = getLeafFolders(); 521 Collection t_cPackages = getPackages(); 522 StringBuffer t_sbTopFolders = new StringBuffer(); 523 StringBuffer t_sbLeafFolders = new StringBuffer(); 524 StringBuffer t_sbPackages = new StringBuffer(); 525 526 if (t_strProjectName != null) 527 { 528 MessageFormat t_Formatter = null; 529 530 t_sbResult.append(getHeader()); 531 532 if (t_cTopFolders != null) 533 { 534 Iterator t_itTopFolders = t_cTopFolders.iterator(); 535 536 while (t_itTopFolders.hasNext()) 537 { 538 t_sbTopFolders.append(" " + t_itTopFolders.next()); 539 } 540 } 541 542 if (t_cLeafFolders != null) 543 { 544 t_Formatter = new MessageFormat(getJarDepsSubtemplate()); 545 546 Iterator t_itLeafFolders = t_cLeafFolders.iterator(); 547 548 while (t_itLeafFolders.hasNext()) 549 { 550 t_sbLeafFolders.append( 551 t_Formatter.format( 552 new Object[] 553 { 554 t_itLeafFolders.next() 555 })); 556 } 557 } 558 559 if (t_cPackages != null) 560 { 561 Iterator t_itPackages = t_cPackages.iterator(); 562 563 while (t_itPackages.hasNext()) 564 { 565 t_sbPackages.append(" " + t_itPackages.next()); 566 } 567 } 568 569 t_Formatter = new MessageFormat(getBody()); 570 571 t_sbResult.append( 572 t_Formatter.format( 573 new Object[] 574 { 575 t_strProjectName.toLowerCase(), 576 t_strProjectName, 577 t_sbTopFolders, 578 t_sbLeafFolders, 579 t_sbPackages 580 581 })); 582 } 583 584 return t_sbResult.toString(); 585 } 586 }

This page was automatically generated by Maven